home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 8.2 KB | 252 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFctClp.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding
- #endif
-
- FW_DEFINE_AUTO(FW_CFacetClipper)
-
- //========================================================================================
- // class FW_CFacetClipper
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::FW_CFacetClipper
- //----------------------------------------------------------------------------------------
-
- FW_CFacetClipper::FW_CFacetClipper(Environment* ev, FW_CPart* part):
- fPart(part)
- {
- FW_UNUSED(ev);
- FW_ASSERT(part);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::~FW_CFacetClipper
- //----------------------------------------------------------------------------------------
-
- FW_CFacetClipper::~FW_CFacetClipper()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::Clip
- //----------------------------------------------------------------------------------------
- // limitShape is in content coordinate
-
- void FW_CFacetClipper::Clip(Environment *ev, FW_CPresentation *presentation, ODShape* limitShape)
- {
- FW_ASSERT(presentation);
-
- FW_CPresentationFrameIterator ite(ev, presentation);
- for (FW_CEmbeddingFrame* frame = (FW_CEmbeddingFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (FW_CEmbeddingFrame*)ite.Next(ev))
- {
- Clip(ev, frame, limitShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::Clip
- //----------------------------------------------------------------------------------------
- // limitShape is in content coordinate
-
- FW_DECLARE_THROW_POINT (FW_CFacetClipper_Clip);
-
- void FW_CFacetClipper::Clip(Environment *ev, FW_CEmbeddingFrame* frame, ODShape* limitShape)
- {
- FW_CFrameFacetIterator iter(ev, frame);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
- ClipEmbeddedFacets(ev, frame, facet, limitShape);
- FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::ClipEmbeddedFacets
- //----------------------------------------------------------------------------------------
-
- void FW_CFacetClipper::ClipEmbeddedFacets(Environment *ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* containingFacet,
- ODShape* limitShape)
- {
- FW_CAcquiredODShape aqLimitShape;
-
- // ----- Transform limitShape to frame coordinate -----
- if (limitShape)
- {
- aqLimitShape = limitShape->Copy(ev);
- FW_ContentToFrame(ev, embeddingFrame->GetODFrame(ev), aqLimitShape);
- aqLimitShape->SetGeometryMode(ev, kODLoseGeometry);
- }
-
- // ----- Calculate the working clip and intersect it with the limitShape -----
- FW_CAcquiredODShape aqWorkingClip = AcquireWorkingClip(ev, embeddingFrame, containingFacet, aqLimitShape);
-
- // ----- Now iterates -----
- FW_CFacetIterator iter(ev, containingFacet, kODChildrenOnly, kODFrontToBack);
- FW_Boolean doIt;
-
- for (ODFacet* embeddedFacet = iter.First(ev);
- iter.IsNotComplete(ev);
- embeddedFacet = iter.Next(ev))
- {
- doIt = TRUE;
-
- if (aqLimitShape != (ODShape*)NULL)
- {
- FW_CAcquiredODShape aqResult(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
-
- FW_CAcquiredODTransform aqTransform = embeddedFacet->AcquireExternalTransform(ev, NULL);
- aqResult->Transform(ev, aqTransform); // containing Frame Coordinate
-
- aqResult->SetGeometryMode(ev, kODLoseGeometry);
-
- aqResult->Intersect(ev, aqLimitShape);
-
- doIt = !aqResult->IsEmpty(ev);
- }
-
- if (doIt)
- ClipOneEmbeddedFacet(ev, embeddedFacet, aqWorkingClip);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::ClipOneEmbeddedFacet
- //----------------------------------------------------------------------------------------
-
- FW_DECLARE_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
-
- void FW_CFacetClipper::ClipOneEmbeddedFacet(Environment *ev,
- ODFacet* embeddedFacet,
- ODShape* workingClip)
- {
- // Although we don't modify this transform, we need to protect ourself against someone
- // else changing it (in a threaded environment) between the time we use it now (A) and
- // at the exit of this method (B). This is not efficient.
- FW_CAcquiredODTransform aqTransform = FW_CopyAndRelease (ev,
- embeddedFacet->AcquireWindowFrameTransform(ev, NULL));
-
- // ----- Transform my working clip to embedded frame coordinates -----
- workingClip->InverseTransform(ev, aqTransform); // (A)
-
- FW_TRY
- {
- // ----- Set the clip of embFrame -----
-
- FW_CAcquiredODShape aqEmbeddedClipShape(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
- aqEmbeddedClipShape->SetGeometryMode(ev, kODLoseGeometry);
- FW_CAcquiredODShape aqFrameShape = FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireFrameShape(ev, NULL));
- aqFrameShape->SetGeometryMode(ev, kODLoseGeometry);
-
- aqEmbeddedClipShape->Intersect(ev, aqFrameShape);
- aqEmbeddedClipShape->Intersect(ev, workingClip);
-
- FW_CHECK_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
-
- // This probably won't fail (it will release existing objects and acquire these)
- embeddedFacet->ChangeGeometry(ev, aqEmbeddedClipShape, NULL, NULL); // Set the clip of the embedded facet. embeddedClipShape is kept by the facet
-
- // ----- remove embeddedClipShape of the working clip -----
- workingClip->Subtract(ev, aqEmbeddedClipShape);
-
- FW_CHECK_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING () {
- workingClip->Transform(ev, aqTransform); // (B)
- FW_THROW_SAME ();
- }
- FW_CATCH_END
-
- // ----- Put back working clip in window coordinates -----
- workingClip->Transform(ev, aqTransform); // (B)
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFacetClipper::AcquireWorkingClip
- //----------------------------------------------------------------------------------------
- // returns the working clip and intersect it with limitshape (Frame coordinate)
-
- ODShape* FW_CFacetClipper::AcquireWorkingClip(Environment *ev,
- FW_CEmbeddingFrame* embeddingFrame,
- ODFacet* containingFacet,
- ODShape* limitShape)
- {
- FW_CPoint extent;
- embeddingFrame->GetContentExtent(ev, extent);
- FW_CRect extentRect(FW_kFixed0, FW_kFixed0, extent.x, extent.y);
-
- // ----- Create the working clip (use the content shape or extent rect if static canvas) -----
- ODShape* workingClip;
- if (containingFacet->GetCanvas(ev)->IsDynamic(ev))
- workingClip = embeddingFrame->AcquireContentShape(ev); // in Frame Coordinate
- else
- {
- embeddingFrame->GetContentView(ev)->ViewContentToFrame(ev, extentRect);
- workingClip = ::FW_NewODShape(ev, extentRect);
- }
- workingClip->SetGeometryMode(ev, kODLoseGeometry);
-
- if (limitShape)
- limitShape->Intersect(ev, workingClip);
-
- // ----- Transform it into window coordinate -----
- FW_CAcquiredODTransform aqWindowContentTransform(containingFacet->AcquireWindowFrameTransform(ev, NULL));
- workingClip->Transform(ev, aqWindowContentTransform); // now in window coordinate
-
- return workingClip;
- }
-